package Top_Interview_Questions_Review._008Two_Pointers;

/**
 * @Author: 吕庆龙
 * @Date: 2020/3/11 15:31
 * <p>
 * 功能描述:
 */
public class _0026 {

    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        _0026 test = new _0026();
        test.removeDuplicates(nums);
    }

    /**
     * https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/solution/shuang-zhi-zhen-shan-chu-zhong-fu-xiang-dai-you-hu/
     */
    public int removeDuplicates(int[] nums) {
        if (nums.length == 0) return 0;
        int i = 0;
        for (int j = 1; j < nums.length; j++) {
            if (nums[j] != nums[i]) {
                i++;
                nums[i] = nums[j];
            }
        }
        return i + 1;
    }


}
